#ifndef __WAVEFORM_H__
#define __WAVEFORM_H__
/***********************************************
#
#      Filename: waveform.h
#
#        Author: huangyifei - bupt.huangyifei@gmail.com
#        Create: 2021-11-23 12:04:34
***********************************************/


#include <stdint.h>

#include <string>
#include <vector>
#include <map>

#include "indication.h"

namespace ch {

static const int SamplingRate = 1000;
static const double PI = 3.14159265;
static const double Raw2mV = 0.00252f;

static const size_t ChannelCount = 12;
enum Channel {
    I,II,III,aVR,aVL,aVF,V1,V2,V3,V4,V5,V6,None
};

static const size_t TagCount = 11;
enum HeartbeatTag {
    Ps,P,Pe,Rs,Q,R,S,Re,Ts,T,Te
};

static const size_t HeartbeatChannelCount = 3;

struct Heartbeat {
    size_t tags[ChannelCount][TagCount];
    size_t combineTags[TagCount]; // Combined according to mHeartbeatChannel
};

class Waveform {
public:
    explicit Waveform();
    ~Waveform();
    void Load(const std::string dataPath, const std::string heartbeatPath);
    void Save(const std::string dataPath, const std::string heartbeatPath);
    std::vector<int16_t> const GetWaveform(size_t i);
    std::vector<Heartbeat> const GetHeartbeats();
    int GetIndication(Indication&);
    int SwapChannel(Channel i, Channel j);
    int ReverseChannel(Channel i);
    int SetHeartbeatChannels(Channel c1, Channel c2, Channel c3);
    int SetHeartbeat(const Heartbeat& hb, size_t index);
private:
    void CalculateDuration(Indication&);
    double CalculateSingleVolt(Channel,HeartbeatTag);
    void CalculateVolt(Indication&);
    double CalculateSingleAxis(HeartbeatTag);
    void CalculateAxis(Indication&);
    void CalculateCombineTags();
    std::vector<int16_t> mWaveform[ChannelCount]; // convert to millvolt by *2.52
    std::vector<Heartbeat> mHeartbeats;
    Channel mHeartbeatChannel[HeartbeatChannelCount];
};
}
#endif //__WAVEFORM_H__
